home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 134_01.zip / CMDUTIL.NRO < prev    next >
Text File  |  1993-06-12  |  13KB  |  375 lines

  1. .so AN.NRO
  2. .TH abbrev 3 "Test for valid abbreviation"
  3. .SH NAME
  4. abbrev - Test for valid abbreviation
  5. .SH SYNOPSIS
  6. .nf
  7. .nj
  8. .in +4
  9. .ti -4
  10. int abbrev (text, pattern)
  11. char *text;
  12. char *pattern;
  13. .in -4
  14. .fi
  15. .ju
  16. .br
  17. .SH DESCRIPTION
  18. Abbrev tests whether or not the input string, "text", is a valid
  19. abbreviation of the pattern string, "pattern".  The pattern is a string
  20. giving the input expected, with mandatory characters in uppercase and
  21. optional ones in lowercase.  The function returns TRUE if the text
  22. string contains all of the required characters, and no other characters
  23. except for any optional ones.
  24. .SH EXAMPLES
  25. .nf
  26. .nj
  27. abbrev ("EXACT", "EXACT") == TRUE;
  28. abbrev ("exact", "EXACT") == TRUE;
  29. abbrev ("e", "EXACT") == FALSE;
  30. abbrev ("e", "Exact") == TRUE;
  31. abbrev ("x", "eXact") == TRUE;
  32. abbrev ("ext", "eXact") == TRUE;
  33. abbrev ("xray", "eXact") == FALSE;
  34. .fi
  35. .ju
  36. .SH "RETURN VALUE"
  37. The function returns TRUE if the "text" input is a valid abbreviation
  38. of the "pattern" input, and FALSE otherwise.
  39. .SH "SEE ALSO"
  40. procarg(7)
  41. .SH NOTES
  42. Abbrev is particularly useful in allowing abbreviations for arguments on a
  43. user command line.  For instance, if there is a PAGENUMBER option, with
  44. any abbreviation containing PN acceptable, then the call:
  45. .sp
  46. abbrev (argv [k], "PageNumber");
  47. .sp
  48. would return TRUE if the k'th argument specifies the PAGENUMBER option and
  49. FALSE otherwise.
  50. .bp
  51. .TH initv 3 "Initialize a vector of integers"
  52. .SH NAME
  53. initv - Initialize a vector of integers
  54. .SH SYNOPSIS
  55. .nf
  56. .nj
  57. .br
  58. initv (vector, endflag, value0, value1, ... , endflag)
  59. .in +5
  60. int * vector;
  61. int endflag;
  62. int value0, value1, ... ;
  63. .in -4
  64. .fi
  65. .ju
  66. .SH DESCRIPTION
  67. .PP
  68. Initv provides an alternative to Zolman's "initw" function for initializing
  69. a list of integers (actually, of any 16-bit quantities).  In addition
  70. to allowing the vector content to be specified numerically, it will allow
  71. initializing with symbolic constants, arithmetic expressions, or even strings.
  72. .PP
  73. To use initv, perform a call of the form above.  "Vector" is the vector to
  74. be initialized; value0 through valuen are arguments to be stored in locations
  75. 0 through n of the vector.
  76. Endflag is a special value that marks the end of the list.  It must not be the
  77. same as any of the values value0, ..., valuen.  It is supplied once at the
  78. beginning of the list, to indicate its value; its occurrence at the end of
  79. the list stops that movement of data.
  80. .ul 1
  81. NOTE: Endflag is stored in vector [n+1].
  82. .SH CAVEATS
  83. .PP
  84. Vector must be large enough to hold all the values supplied,
  85. .ul 1
  86. plus the value of endflag.
  87. If vector is too small, the excess values will overwrite memory locations
  88. following the end of the array, with unpredictable results.
  89. .PP
  90. The "endflag" value must not appear in the list of values.  If it does,
  91. the movement of the data will terminate prematurely when the occurrence
  92. of "endflag" is reached.
  93. .SH EXAMPLES
  94. .nf
  95. .nj
  96. struct {
  97. .in +5
  98. char * name;
  99. int number;
  100. } numnames [11];
  101. .in -5
  102. initv (numnames, EOF,
  103. .in +5
  104. "zero", 0, "one", 1, "two", 2, "three", 3,
  105. "four", 4, "five", 5, "six", 6, "seven", 7,
  106. "eight", 8, "nine", 9, "ten", 10, EOF);
  107. .in -5
  108. .fi
  109. .ju
  110. .SH "RETURN VALUE"
  111. The return value is unspecified.
  112. .SH NOTES
  113. This function would be TOTALLY unnecessary if BDS C had initializers.
  114. .bp
  115. .TH patmat 3 "Name pattern matcher"
  116. .SH NAME
  117. patmat - Name pattern matcher
  118. .SH SYNOPSIS
  119. .nf
  120. .nj
  121. int patmat (name, pattern, equiv, newname)
  122. .in +4
  123. char * name;      /* Name to be matched with the pattern */
  124. char * pattern;   /* Pattern to match it with */
  125. char * equiv;     /* Pattern for output name or 0 */
  126. char * newname;   /* Output name */
  127. .in -4
  128. .fi
  129. .ju
  130. .SH DESCRIPTION
  131. .PP
  132. Patmat is a generalized procedure for working with "wild card" names
  133. using the '*' and '?' conventions.  It is superior to the wild card
  134. matcher provided in the CP/M BDOS in that it will allow operating on
  135. named objects other than files.  It also will allow (and process correctly)
  136. asterisks anywhere in the pattern; the pattern "*1.ASM" will find any
  137. ".ASM" files whose names end in 1, no matter how long the names are.
  138. .PP
  139. There are two calling sequences for patmat.  In the first, one is interested
  140. merely in whether or not a name matches a pattern.  In this calling sequence,
  141. the name is passed as the first argument, and the pattern (possibly
  142. containing question marks and asterisks) is given as the second.  The
  143. third argument ("equiv") is zero, and the fourth ("newname") need not be
  144. supplied.
  145. .PP
  146. In the second calling sequence, the user also wishes to make an output
  147. file name from the input name, in order to process requests like
  148. .cu 1
  149. PIP *.BAK=*.C
  150. In this case, the first two arguments are as above.  The third argument
  151. "equiv" is the pattern to be used for the output name ("*.BAK" in the
  152. example) and the fourth is a pointer to a character vector which will
  153. receive the name.
  154. .PP
  155. Question marks are not permitted in the "equiv" argument, but asterisks
  156. are.  Each asterisk in the "equiv" string matches either (1) a single
  157. asterisk in the input string, or (2) any number of consecutive question
  158. marks in the input string.  
  159. .SH EXAMPLES
  160. .nf
  161. .nj
  162. if (patmat (filename, "*.COM", 0))
  163. .in +4
  164. do_file (filename);
  165. .in -4
  166. .sp
  167. if (patmat (filename, "*.*", "*.BAK", outname))
  168. .in +4
  169. copy_file (filename, outname);
  170. .in -4
  171. .fi
  172. .ju
  173. .SH "RETURN VALUE"
  174. .PP
  175. In both calling sequences, the returned value is TRUE if the
  176. name matched the pattern, and FALSE otherwise.
  177. .SH "SEE ALSO"
  178. unscaf (3)
  179. .SH NOTES
  180. .PP
  181. The "patmat" procedure, since it is intended for more things than just
  182. file names, does not make any BDOS calls.  If it is being used as a file
  183. name matcher,  it should be called once for each file in the directory,
  184. using the file name as formatted for printing.  The "unscaf" procedure,
  185. which converts a file name back to printable format, may be used to
  186. accomplish this, in conjunction with calls to BDOS functions 17 and 18
  187. (search for first/next).
  188. .bp
  189. .TH procarg 3 "Command argument processor"
  190. .SH NAME
  191. procarg - command line argument processor
  192. .SH SYNOPSIS
  193. .bo 5
  194. .nf
  195. .nj
  196. .in +5
  197. .br
  198. int procarg (argcp, argvp, optable, infop)
  199. int *argcp;             /* Pointer to the "argc"
  200.                            word of main program */
  201. char ***argvp;          /* Pointer to the "argv"
  202.                            word of main program */
  203. struct option * optable;
  204.                         /* Option table (see text) */
  205. char ***infop;          /* Pointer to a return 
  206.                            value (see text)        */
  207. .in -5
  208. .fi
  209. .ju
  210. .br
  211. .SH DESCRIPTION
  212. .PP
  213. The "procarg" function provides a common means for all command
  214. processors to obtain command-line arguments.  A standard abbreviation
  215. discipline is supported, and the procedure is compatible with the
  216. "showsyntax" function (q.v.), which displays command syntax to the user.
  217. .PP
  218. The first two arguments are pointers to the "argc" and "argv" words of the
  219. main function. The third argument is a pointer to an option table.  The
  220. option table is a vector of two-word quantities; the first word is 
  221. a string pointer designating the
  222. name of an option, and the second is the type of the option.  
  223. The table is terminated by a pointer containing the symbolic constant EOF.
  224. The fourth argument to "procarg" is a pointer to a word which will receive
  225. a return value, which depends on the option type.
  226. .PP
  227. Option names are a mix of lowercase and uppercase characters.  Any
  228. uppercase characters in the name are mandatory; lowercase characters
  229. are optional.  Thus, an entry of "eXtract" in the option table would
  230. match "-x", "-ext", "-xtr", or anything similar, but would not match
  231. "-etrct", "-xray" or "foobar".  
  232. .PP
  233. Option types are specified as symbolic constants (available in the
  234. include file "cmdutil.h").  The constants, and their effects, are as follows:
  235. .sp
  236. NAKED_KWD
  237. .sp
  238. .br
  239. .in +5
  240. Specifies that the option is a keyword option ("-foo") with no associated
  241. value.  If a NAKED_KWD option is detected, the "info" word in the calling
  242. sequence will be set to 0.
  243. .in -5
  244. .br
  245. .sp
  246. SVAL_KWD
  247. .sp
  248. .br
  249. .in +5
  250. Specifies that the option is a keyword option accepting a string value
  251. ("-foo bar").  If a SVAL_KWD option is detected, the "info" word in the
  252. calling sequence will designate the string that was supplied.
  253. .in -5
  254. .br
  255. .sp
  256. NVAL_KWD
  257. .sp
  258. .br
  259. .in +5
  260. Specifies that the option is a keyword option accepting a numeric value
  261. ("-foo 17").  If an NVAL_KWD option is detected, the "info" word in the
  262. calling sequence will contain the binary value of the number.
  263. .in -5
  264. .br
  265. .sp
  266. MSVL_KWD
  267. .sp
  268. .br
  269. .in +5
  270. Specifies that the option accepts several string values ("-foo bar zot baz").
  271. If an MSVL_KWD is detected, the "info" word designates a vector of 16-bit
  272. quantities.  The first of these is the number of strings that were found;
  273. it is followed by pointers to each of the strings.
  274. .in -5
  275. .br 
  276. .sp
  277. MNVL_KWD
  278. .sp
  279. .br
  280. .in +5
  281. Specifies that the option accepts several numeric values ("-foo 17 39 -8").
  282. If an MNVL_KWD option is detected, the "info" word designates a vector of
  283. 16-bit integers.  The first of these is the number of values that were
  284. found; it is followed by the binary representations of the values themselves.
  285. .in -5
  286. .br
  287. .PP
  288. If no option is found to match a particular command line argument, the
  289. "info" word will be a string pointer designating the argument itself.
  290. .SH CAVEATS
  291. .PP
  292. If "dio" or "wildexp" are used as part of command line processing,
  293. they should be called *before* beginning to handle the command's
  294. arguments with "procarg".
  295. .SH EXAMPLES
  296. .PP
  297. Any example of "procarg" is of necessity rather lengthy.  The file, DIFF.C,
  298. on the same disc as CMDUTIL.C, is a non-trivial example of a command
  299. processor using "procarg".
  300. .SH FILES
  301. .PP
  302. The %include file CMDUTIL.H contains definitions of the "option" structure
  303. and of the symbolic values for the option types.
  304. .SH "RETURN VALUE"
  305. .PP
  306. The return value is the index into "optable" (which is assumed to be
  307. an array of "struct option") of a table entry which matched a command
  308. line argument, or one of the following special values:
  309. .PP
  310. -1 indicates that the argument did not appear to be an option.  Either
  311. it did not begin with a hyphen, or it began with a hyphen followed by
  312. a non-alphabetic character.  The "info" word is a string pointer designating
  313. the argument.
  314. .PP
  315. -2 indicates that the argument appeared to be an option, but was not
  316. recognizable.  Either it did not appear in "optable", or it was specified
  317. with SVAL_KWD or NVAL_KWD but no value followed it.
  318. .PP
  319. Upon return from "procarg", the "argc" and "argv" words have been adjusted
  320. to designate the next command line argument.  "argv" will have been
  321. advanced around the option and any values following it; "argc" will have
  322. been decreased accordingly.
  323. .SH "SEE ALSO"
  324. .nf
  325. .nj
  326. abbrev (3) for the abbreviation algorithm.
  327. cmdutil.h (7)
  328. initv (3)  for an easy way to set up the "optable" array.
  329. showsyntax (3) for a way to report the command syntax.
  330. .fi
  331. .ju
  332. .SH "WARNINGS"
  333. .PP
  334. The following messages can be printed on the user's console at run time:
  335. .sp
  336. "xxx: unknown option."  -- An argument of the form "-bar" was supplied,
  337. but "bar" did not match any of the entries in optable.
  338. .sp
  339. "xxx option requires a value." -- An argument of the form "-bar" was
  340. supplied with no value after it, but optable called it n SVAL_KWD or
  341. MVAL_KWD.
  342. .SH "DIAGNOSTICS"
  343. .PP
  344. It is recommended that any command with incorrect syntax include a call
  345. to "showsyntax" to indicate to the user what the correct syntax is.
  346. .SH BUGS
  347. .PP
  348. Non-numeric characters in options specified with NVAL_KWD and MNVL_KWD are
  349. not detected; results will be unpredictable.
  350. .bp
  351. .TH showsyntax 3 "Display command syntax"
  352. .SH NAME
  353. showsyntax -- Display command syntax.
  354. .SH SYNOPSIS
  355. .nf
  356. .nj
  357. showsyntax (command, optable)
  358. char * command;
  359. struct option * optable;
  360. .fi
  361. .ju
  362. .SH DESCRIPTION
  363. .PP
  364. Showsyntax displays the correct syntax for a command on the user's console.
  365. The "command" string gives the command name and any non-keyword arguments;
  366. the "optable" argument is the same as for "procarg" (q.v.).
  367. .SH EXAMPLES
  368. showsyntax ("diff <file1> <file2>", optable);
  369. .SH "RETURN VALUE"
  370. The return value is unspecified.
  371. .SH "SEE ALSO"
  372. cmdutil.h (7),
  373. procarg (3)
  374. - An argument of the form "-bar" was
  375. supplied with no value after it, but optable cal